import 'dart:convert';
import 'package:aegis_flutter_sdk/aegis_flutter_sdk.dart';
import 'package:aegis_flutter_sdk/src/pipes/format.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  group('format-pipe', () {
    test('String log', () {
      List<NormalLog> logs = [
        NormalLog(msg: 'info', level: LogType.info),
        NormalLog(msg: 'error', level: LogType.error),
      ];
      formatNormalLogPipe(logs, (res) {
        expect(jsonEncode(logs), jsonEncode(res));
      });
      // formatNormalLogPipe();
    });
    test('map log', () {
      List<NormalLog> logs = [
        NormalLog(msg: {'key': 'value'}, level: LogType.info),
        NormalLog(msg: 'error', level: LogType.error),
      ];
      formatNormalLogPipe(logs, (res) {
        expect(jsonEncode(logs[0].msg), res[0].msg);
        expect(logs[1].msg, res[1].msg);
      });
      // formatNormalLogPipe();
    });
    test('muti-type array log', () {
      List<NormalLog> logs = [
        NormalLog(msg: [
          '22',
          22,
          {'key': 'value'}
        ], level: LogType.info)
      ];
      formatNormalLogPipe(logs, (res) {
        expect(jsonEncode(logs[0].msg), res[0].msg);
      });
      // formatNormalLogPipe();
    });
    test('input Obj', () {
      List<NormalLog> logs = [
        NormalLog(msg: TestObj('name', 'id'), level: LogType.info)
      ];
      formatNormalLogPipe(logs, (res) {
        expect(jsonEncode(logs[0].msg), res[0].msg);
      });
      // formatNormalLogPipe();
    });
  });
}

class TestObj {
  String name;
  String id;
  TestObj(this.name, this.id);
  Map toJson() => {
        'name': name,
        'id': id,
      };
}
